﻿/*****************************************************************//**
 * @file    FITKGraphObjectModelBase.h
 * @brief   Geometry graph object base for VTK graph widget.

 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-12-02
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTMODELBASE_H__
#define __FITKGRAPHOBJECTMODELBASE_H__

#include "FITKGraphObject3D.h"

#include "FITKVTKGraphAdaptorAPI.h"

#include <QVector>

// Forward declaration
class FITKGraphActor;

namespace Exchange
{
    class FITKGraphObjectModelHighlighting;
    class FITKColorMap;
}

/**
 * @brief   The view mode of the model.
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-04-26
 */
enum ModelViewMode
{
    // Edges and surfaces.
    ModelShaded = 0,

    // The special wireframe view mode.
    ModelHidden,

    // Edges.
    ModelWireframe
};

/**
 * @brief   The color strategy mode enum.
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-05-11
 */
enum ColorMode
{
    ColorNone = -1,
    ColorDefault = 0,
    ColorDefaultProperty = 1,
    ColorSection = 2,
    ColorMaterial = 3,
    ColorDoubleFaces = 4,
    ColorDefaultMesh = 5,
};

namespace Exchange
{
    /**
     * @brief   Geometry graph object base for VTK graph widget.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-12-02
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectModelBase : public FITKGraphObject3D
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectModelBase, FITKGraphObject3D);
        FITKCLASS(Exchange, FITKGraphObjectModelBase);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   dataObj: The data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        FITKGraphObjectModelBase(AbaqusData::FITKDataCase* caseData, Core::FITKAbstractDataObject* dataObj);

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual ~FITKGraphObjectModelBase() = default;

        /**
         * @brief   Enable or disable transparent.[virtual]
         * @param   isOn: Enable or disable
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void setTransparent(bool isOn);

        /**
         * @brief   Set the visibility of the model's feature edges or points actor.[virtual]
         * @param   visibility: The visibility of the actor
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void setFeatureVisible(bool visibility);

        /**
         * @brief   Highlight model.[virtual][override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight model.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void disHighlight() override;

        /**
         * @brief   Pre-highlight the graph actors.[virtual][override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void preHighlight() override;

        /**
         * @brief   Show or hide the model points.[virtual]
         * @param   visible: The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void setPointVisible(bool visible);

        /**
         * @brief   Set the point properties if the points are visible.[virtual]
         * @param   pixelSize: The point pixel size[default]
         * @param   color: The point color[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void setPointProperties(int pixelSize = 6, QColor color = Qt::red);

        /**
         * @brief   Set the color mode by the enum value.( Equals to functions 'colorByXXXXX'. )
         * @param   mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-11
         */
        void setColorMode(ColorMode mode);

        /**
         * @brief   Get current color mode.
         * @return  The color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        ColorMode getCurrentColorMode();

        /**
         * @brief   Set the graph actors to the default color.[pure virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void colorByDefault(bool forceUpdate = false) = 0;

        /**
         * @brief   Set the graph actors with the material's color.[pure virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void colorByMaterial(bool forceUpdate = false) = 0;

        /**
         * @brief   Set the graph actors with the section's color.[pure virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void colorBySection(bool forceUpdate = false) = 0;

        /**
         * @brief   Set the graph actors to the default property color.[pure virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void colorByDefaultProperty(bool forceUpdate = false) = 0;

        /**
         * @brief   Enable back face color.[pure virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void colorByDoubleFaces(bool forceUpdate = false) = 0;

        /**
         * @brief   Set the graph actors to the default mesh color.[pure virtual]
         * @param   forceUpdate: Force update the color mode
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-13
         */
        virtual void colorByDefaultMesh(bool forceUpdate = false) = 0;

    protected:
        /**
         * @brief   Initialize.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        virtual void init();

    protected:
        /**
         * @brief   The graph object for highlighting the model.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        FITKGraphObjectModelHighlighting* m_graphObjHighlight{ nullptr };

        /**
         * @brief   The graph object for pre-highlighting the model.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        FITKGraphObjectModelHighlighting* m_graphObjPreHighlight{ nullptr };

        // For colors.
        //@{

        /**
         * @brief   The color map key words for showing default model color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        const QString c_defaultArrName = "Default";

        /**
         * @brief   The color map key words for showing materials color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        const QString c_materialArrName = "Materials";

        /**
         * @brief   The color map key words for showing sections color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        const QString c_sectionArrName = "Sections";

        /**
         * @brief   The color map key words for showing property default color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        const QString c_propDefaultArrName = "PropertyDefault";

        /**
         * @brief   The color map key words for showing mesh default color.[const]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-13
         */
        const QString c_meshDefaultArrName = "MeshDefault";

        /**
         * @brief   Current color mode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-12-02
         */
        ColorMode m_colorMode = ColorMode::ColorNone;
        //@}
    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTMODELBASE_H__
